package com.maxverse.boot.web2image.queue.producer;

import com.maxverse.boot.web2image.common.model.TaskMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TaskProducer {
    private static final String TASK_QUEUE_KEY = "web2image:task:queue";
    
    @Autowired
    private RedisTemplate<String, TaskMessage> taskRedisTemplate;
    
    public void sendTask(TaskMessage message) {
        try {
            taskRedisTemplate.opsForList().rightPush(TASK_QUEUE_KEY, message);
            log.info("Task sent to queue: {}", message.getTaskId());
        } catch (Exception e) {
            log.error("Failed to send task to queue: {}", message.getTaskId(), e);
            throw new RuntimeException("Failed to send task to queue", e);
        }
    }
} 